module.exports = function($scope, $resource, toaster, $state, $modal){

    $scope.data = {};

    $scope.load = function() {
        $resource('/api/as/goc/enterpriserecord/enterpriseinfo', {}, {}).save({}, function(res){
            if (res.errcode === 0) {
                $scope.data = res.data;
            }
        });
    }
    $scope.load();

    //申请备案
	$scope.apply = function(id) {
		$resource('/api/ac/goc/enterpriseRecordService/createEnterprise', {}, {}).save({'id' : id}, function(res){
            if (res.errcode === 0) {
                toaster.success({title: '', body: '申请成功'});
                $scope.load();
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }

    //申请变更
	$scope.applyupdate = function(id) {
        if(confirm("确定要申请变更吗？")) {
            $resource('/api/ac/goc/enterpriseRecordService/updateRecordState', {}, {}).save({'id' : id, 'record_type' : '3'}, function(res){
                if (res.errcode === 0) {
                    toaster.success({title: '', body: '申请变更成功'});
                    $scope.load();
                } else {
                    toaster.error({title: '', body: res.errmsg});
                }
            })
        }
    }
    
    //打开审核记录
    $scope.applyrecord = function(){
     
        var para = $state.get('app.applyrecord');

        var modalInstance = $modal.open(para);
        modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
            console.log('modal is opened');  
        });  
        modalInstance.result.then(function(result) {  

        }, function(reason) {  
            console.log(reason);// 点击空白区域，总会输出backdrop  
            // click，点击取消，则会暑促cancel  
            $log.info('Modal dismissed at: ' + new Date());  
        }); 
    }
    
};